/************************新后台js*********************************/
define(function(require) {
	
	var $ = require('jquery1.7');
	var utils = require("utils");
	var ctx = utils.constants.ctx;

	var userService = require("bean/userService");
	var Confirmbox = require("confirmbox");
	var Validator = require("validator");
	
	$(".wt_handle_userInfo").bind("click",function(){
		var userId = $(this).attr("data").replace("userId_", "");
		window.open(ctx + "/zone/grow_record/" + userId + "#we_main", "_blank");
	});
	
	//修改密码
	var flag = 0;
	$.post(ctx+"/updateUserPassword",function(data){
		var confirmBox = new Confirmbox({
	        trigger: '#updatePassword',
	        title: '修改密码',
	        message: data,
	        onConfirm: function() {
	        	updatePasswordSubmit();
	        }
	    });
		
		confirmBox.after("show",function(){
			/*$("#oldPassword").blur(function(){
				var password = $(this).val();
				if(password!=""){
					if(!userService.checkPassword(password)){
						$(this).next().text("密码有误").css("color","red");
					} else {
						$(this).next().text("请输入旧密码").css("color","#B2B2B2");
					}
				} else {
					$(this).next().text("密码不为空").css("color","red");
				}
			});
			
			
			$("#repeatNewPassword").blur(function(){
				var newPassword = $("#newPassword").val();
				var repeatPassword = $(this).val();
				if(newPassword != repeatPassword){
					$(this).next().text("两次输入密码不一致").css("color","red");
					$("#newPassword").next().text("两次输入密码不一致").css("color","red");
				} else {
					$(this).next().text("请输入密码").css("color","#B2B2B2");
					$("#newPassword").next().text("请确认新密码").css("color","#B2B2B2");
				}
			});*/
			
			
			var validator = new Validator({
	            element: $("#password_form")
	        }).addItem({
	            element: '[name=oldPassword]',
	            required: true,
	            rule: "password"
	        }).addItem({
	            element: '[name=newPassword]',
	            required: true,
	            rule: "password"
	        }).addItem({
	            element: '[name=repeatNewPassword]',
	            required: true,
	            rule: "password"
	        });
		});
		confirmBox.after("hide",function(){
			$("#oldPassword").val("");
			$("#newPassword").val("");
			$("#repeatNewPassword").val("");
		});
	});
	
	function updatePasswordSubmit(){
		
		var oldPassword = $("#oldPassword").val();
		var newPassword = $("#newPassword").val();
		var repeatPassword = $("#repeatNewPassword").val();
		if(!userService.checkPassword(oldPassword)){
			alert("原密码输入有误！");
			return;
		}
		if(newPassword != repeatPassword){
			alert("两次输入密码不一致!");
			return;
		}
		if(userService.updatePassword(oldPassword,newPassword)){
			alert("修改密码成功！");
			location.href = ctx + "/logout";
		} else {
			alert("修改密码成功失败！");
		}
	}

	function startMarquee(){
		var insc;
		var this_div=$('#noticeBackIndexNew').parent();
		var _li=$('#noticeBackIndexNew').next().find("li");
		var realSize=_li.size();
		if(realSize<=1){
			return;
		}
		var _ul=$('#noticeBackIndexNew').next();
		var _height=_li.outerHeight();
		var len=_height*realSize;
		var ul_height=2*len;
		_ul.height(ul_height);
		_li.clone().appendTo(_ul);
		_li.find("a").hover(function(){
			insc=0;
		},function(){
			insc=_height;
		})
		var sc=setInterval(function(){
			l=this_div.scrollTop();
			if(l<len-2){
				this_div.animate({scrollTop:l+insc},200);
			}else{
				this_div.scrollTop(0);
			}
			
		},4000);
	}
	
/*	function rollNews(){
		var this_div=$(".wt_notice_info .detail");
		var _li=$('#noticeBackIndexNew').next().find("li");
		var realSize=_li.size();
		if(realSize<=1){
			return;
		}
		var _ul=$('#noticeBackIndexNew').next();
		var _height=_li.height();
		var insc=_height;
		var len=_height*realSize;
		var ul_height=2*len;
		_ul.height(ul_height);
		_li.clone().appendTo(_ul);
		var sc=setInterval(function(){
			l=this_div.scrollTop();
			if(l<len-10){
				this_div.scrollTop(l+insc);
			}else{
				this_div.scrollTop(0);
			}
			
		},4000);
	}*/
});



